#include<iostream>
#include<cassert>
#include<cstdio>
#include<string>
#include<pthread.h>
#include<unistd.h>
using namespace std;

int g_val = 100;
const std::string fun()
{
    // std::string str("我是一个独立的方法");
    // return str;
    return "我是一个独立的方法";
}
//新线程
void *thread_routine(void* args)
{
    
    const char* name = (const char*)args;
    while(true)
    {
        cout << "我是新线程，我正在运行！name: " << name  << " : " << fun() << " : " <<  ++g_val << "&g_val: " << &g_val << endl;
        sleep(1);
        fun();
    }
}
int main()
{
    pthread_t tid;
    int n = pthread_create(&tid, nullptr, thread_routine, (void*)"thread one");
    assert(0 == n);
    (void)n;


   
    //主线程
    while(true)
    {
        //地址--> ?
        char tidbuffer[64];
        snprintf(tidbuffer, sizeof(tidbuffer), "0x%x", tid);
        cout << "我是主线程，我正在运行！我创建出来的线程的tid: "<< tidbuffer << " : " << fun() << " : " <<  g_val << "&g_val: " << &g_val << endl;
        sleep(1);
    }

    return 0;
}